/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.asu.cse360.model;

import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.joda.time.DateTime;

@Entity
@javax.persistence.Table(name="menu")
public class Menu implements Serializable{

    @Id
    @Column(name="menu_id")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;

    @Column(name="last_modified")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar lastModified;

    @OneToMany
    @JoinTable(
            name="menu_menu_item",
            joinColumns=@JoinColumn(name="menu_id"),
            inverseJoinColumns=@JoinColumn(name="menu_item_id"))
    private List<MenuItem> menuItems;

    /**
     * @return the lastModified
     */
    public DateTime getLastModified() {
        if(lastModified == null){
            return null;
        }else{
            return new DateTime(lastModified);
        }
    }

    /**
     * @param lastModified the lastModified to set
     */
    public void setLastModified(DateTime lastModified) {
        if(lastModified == null){
            this.lastModified = null;
        }else{
            this.lastModified = lastModified.toCalendar(Locale.US);
        }
    }

    /**
     * @return the menuItems
     */
    public List<MenuItem> getMenuItems() {
        return menuItems;
    }

    /**
     * @param menuItems the menuItems to set
     */
    public void setMenuItems(List<MenuItem> menuItems) {
        this.menuItems = menuItems;
    }

    /**
     * @return the id
     */
    public Integer getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }

}
